package edu.szte.ovrt.datahandler.ui.console;

import edu.szte.ovrt.datahandler.model.Item;

/**
 * Menu state for {@link Item} level.
 * 
 * @author Péter Török
 */
public class EditItem extends Menu {
	protected final Item m_item;

	public EditItem(final Item item) {
		m_item = item;
	}

	protected void initialize() {
		m_menuMap.add("Edit key", new IAction() {

			@Override
			public void run() throws ExitAction {
				final String newKey = (new Dialog("New key", true)).getValue();
				if (newKey.length() != 0) {
					m_item.setKey(newKey);
				} else {
					showError("Key cannot be empty.");
				}
			}
		});

		m_menuMap.add("Edit value", new IAction() {

			@Override
			public void run() throws ExitAction {
				final String newValue = (new Dialog("New value for <" + m_item.getKey() + ">", true)).getValue();
				m_item.setValue(newValue);
			}
		});

		m_menuMap.addExit("Back");

	}

	@Override
	protected String getTitle() {

		return "Item <" + m_item.getKey() + "> in [" + "a" + "]";
	}

}
